package com.zxj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.common.pojo.R;
import com.zxj.mapper.CarShopMapper;
import com.zxj.pojo.entity.TbBrand;
import com.zxj.pojo.entity.TbCarType;
import com.zxj.pojo.entity.TbShop;
import com.zxj.pojo.vo.ShopVo;
import com.zxj.service.CarShopService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: clms-seventh
 * @description:
 * @author: 张修杰
 * @create: 2021-07-24 19:10
 **/
@Service
public class CarShopServiceImpl implements CarShopService {
    @Resource
    CarShopMapper carShopMapper;

    @Override
    public R selectAllCarShop() {
        List<TbShop> tbShops =carShopMapper.selectList(null);
        return R.ok().put("AlltbShops",tbShops);
    }

    @Override
    public R selectAllList(Integer areaId) {
        QueryWrapper<TbShop> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("area_id", areaId);
        List<TbShop> tbShops = carShopMapper.selectList(queryWrapper);
        return R.ok().put("shoplist",tbShops);
    }

    @Override
    public R findAllCarShopPage(Integer currentPage, Integer pageSize, ShopVo shopVo) {
        QueryWrapper<TbShop> wrapper=new QueryWrapper<>();

        if (StringUtils.isNotEmpty(shopVo.getSname())){
            wrapper.like("sname",shopVo.getSname());
        }

        if (StringUtils.isNotEmpty(shopVo.getAddress())){
            wrapper.like("address",shopVo.getAddress());
        }
        Page<TbShop> page=new Page<>(currentPage,pageSize);
//        IPage<TbCar> page1=carConfigMapper.SaveCarList(page,wrapper);
        carShopMapper.selectPage(page,wrapper);
        return R.ok().put("records",page.getRecords()).put("total",page.getTotal());

    }

    @Override
    public R updateCarShopById(TbShop tbShop) {
        int i= carShopMapper.updateById(tbShop);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R selectCarShopById(String id) {
        TbShop tbShop=carShopMapper.selectById(id);
        List<String> array=new ArrayList<>();
            array.add(tbShop.getProvinceId());
            array.add(tbShop.getCityId());
            array.add(tbShop.getAreaId());
        return R.ok().put("tbShop",tbShop).put("City",array);
    }

    @Override
    public R insertCarShop(TbShop tbShop) {
        int i= carShopMapper.insert(tbShop);
        return (i>0)? R.ok():R.error();
    }

    @Override
    public R deleteCarShop(String id) {
        int i= carShopMapper.deleteById(id);
        return (i>0)? R.ok():R.error();
    }
}
